{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from mxnet import nd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['NDArray', '_Null', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_internal', '_random_helper', 'current_context', 'exponential', 'gamma', 'generalized_negative_binomial', 'multinomial', 'negative_binomial', 'normal', 'numeric_types', 'poisson', 'shuffle', 'uniform']\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "当我们想知道⼀个模块⾥⾯提供了哪些可以调⽤的函数和类的时候，可以使⽤dir函数。下⾯我\n",
    "们打印nd.random模块中所有的成员或属性。\n",
    "'''\n",
    "print(dir(nd.random))\n",
    "'''\n",
    "uniform:均匀分布采样\n",
    "normal:正态分布采样\n",
    "poisson:泊松分布采样\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function ones_like:\n",
      "\n",
      "ones_like(data=None, out=None, name=None, **kwargs)\n",
      "    Return an array of ones with the same shape and type\n",
      "    as the input array.\n",
      "    \n",
      "    Examples::\n",
      "    \n",
      "      x = [[ 0.,  0.,  0.],\n",
      "           [ 0.,  0.,  0.]]\n",
      "    \n",
      "      ones_like(x) = [[ 1.,  1.,  1.],\n",
      "                      [ 1.,  1.,  1.]]\n",
      "    \n",
      "    \n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    data : NDArray\n",
      "        The input\n",
      "    \n",
      "    out : NDArray, optional\n",
      "        The output NDArray to hold the result.\n",
      "    \n",
      "    Returns\n",
      "    -------\n",
      "    out : NDArray or list of NDArrays\n",
      "        The output of this function.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "查找特定函数和类的使用\n",
    "了解某个函数或者类的具体⽤法时，可以使⽤help函数。让我们以NDArray中的ones_like函数为例，查阅它的用法\n",
    "'''\n",
    "help(nd.ones_like)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\n",
       "[[1. 1. 1.]\n",
       " [1. 1. 1.]]\n",
       "<NDArray 2x3 @cpu(0)>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "从 ⽂档信息我们了解到， ones_like函数会创建和输⼊NDArray形状相同且元素为1的新NDArray。我们可以验证⼀下。\n",
    "'''\n",
    "x = nd.array([[0,0,0],[2,2,2]])\n",
    "y = x.ones_like()\n",
    "y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[1;31mSignature:\u001b[0m\n",
       "\u001b[0mnd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrandom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0muniform\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m\n",
       "\u001b[0m    \u001b[0mlow\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
       "\u001b[0m    \u001b[0mhigh\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
       "\u001b[0m    \u001b[0mshape\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0m_Null\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
       "\u001b[0m    \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0m_Null\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
       "\u001b[0m    \u001b[0mctx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
       "\u001b[0m    \u001b[0mout\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
       "\u001b[0m    \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
       "\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
       "\u001b[1;31mDocstring:\u001b[0m\n",
       "Draw random samples from a uniform distribution.\n",
       "\n",
       "Samples are uniformly distributed over the half-open interval *[low, high)*\n",
       "(includes *low*, but excludes *high*).\n",
       "\n",
       "Parameters\n",
       "----------\n",
       "low : float or NDArray\n",
       "    Lower boundary of the output interval. All values generated will be\n",
       "    greater than or equal to low. The default value is 0.\n",
       "high : float or NDArray\n",
       "    Upper boundary of the output interval. All values generated will be\n",
       "    less than high. The default value is 1.0.\n",
       "shape : int or tuple of ints\n",
       "    The number of samples to draw. If shape is, e.g., `(m, n)` and `low` and\n",
       "    `high` are scalars, output shape will be `(m, n)`. If `low` and `high`\n",
       "    are NDArrays with shape, e.g., `(x, y)`, then output will have shape\n",
       "    `(x, y, m, n)`, where `m*n` samples are drawn for each `[low, high)` pair.\n",
       "dtype : {'float16','float32', 'float64'}\n",
       "    Data type of output samples. Default is 'float32'\n",
       "ctx : Context\n",
       "    Device context of output. Default is current context. Overridden by\n",
       "    `low.context` when `low` is an NDArray.\n",
       "out : NDArray\n",
       "    Store output to an existing NDArray.\n",
       "\n",
       "\n",
       "Examples\n",
       "--------\n",
       ">>> mx.nd.random.uniform(0, 1)\n",
       "[ 0.54881352]\n",
       "<NDArray 1 @cpu(0)\n",
       ">>> mx.nd.random.uniform(0, 1, ctx=mx.gpu(0))\n",
       "[ 0.92514056]\n",
       "<NDArray 1 @gpu(0)>\n",
       ">>> mx.nd.random.uniform(-1, 1, shape=(2,))\n",
       "[ 0.71589124  0.08976638]\n",
       "<NDArray 2 @cpu(0)>\n",
       ">>> low = mx.nd.array([1,2,3])\n",
       ">>> high = mx.nd.array([2,3,4])\n",
       ">>> mx.nd.random.uniform(low, high, shape=2)\n",
       "[[ 1.78653979  1.93707538]\n",
       " [ 2.01311183  2.37081361]\n",
       " [ 3.30491424  3.69977832]]\n",
       "<NDArray 3x2 @cpu(0)>\n",
       "\u001b[1;31mFile:\u001b[0m      e:\\anaconda\\envs\\gluon\\lib\\site-packages\\mxnet\\ndarray\\random.py\n",
       "\u001b[1;31mType:\u001b[0m      function\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "'''\n",
    "使用 ? 号来查看文档帮助\n",
    "'''\n",
    "nd.random.uniform?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
